/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modelo;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Andre
 */
@Entity
@Table(name = "condicoescompra")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Condicoescompra.findAll", query = "SELECT c FROM Condicoescompra c"),
    @NamedQuery(name = "Condicoescompra.findByIdCondicoesCompra", query = "SELECT c FROM Condicoescompra c WHERE c.idCondicoesCompra = :idCondicoesCompra")})
public class Condicoescompra implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "idCondicoesCompra", nullable = false)
    private Integer idCondicoesCompra;
    
    @JoinTable(name = "titulocondicoescompra", joinColumns = {
        @JoinColumn(name = "idCondicoesCompra", referencedColumnName = "idCondicoesCompra", nullable = false)}, inverseJoinColumns = {
        @JoinColumn(name = "idTitulo", referencedColumnName = "idTitulo", nullable = false),
        @JoinColumn(name = "parcela", referencedColumnName = "parcela", nullable = false)})
    @ManyToMany
    private List<Titulopagar> titulopagarList;
    
    @JoinColumn(name = "idCondicaoPagamento", referencedColumnName = "idCondicaoPagamento", nullable = false)
    @ManyToOne(optional = false)
    private Condicaopagamento condicaoPagamento;
    
    @JoinColumn(name = "idCompra", referencedColumnName = "idCompra", nullable = false)
    @ManyToOne(optional = false)
    private Compra compra;

    public Condicoescompra() {
    }

    public Condicoescompra(Integer idCondicoesCompra) {
        this.idCondicoesCompra = idCondicoesCompra;
    }

    public Integer getIdCondicoesCompra() {
        return idCondicoesCompra;
    }

    public void setIdCondicoesCompra(Integer idCondicoesCompra) {
        this.idCondicoesCompra = idCondicoesCompra;
    }

    @XmlTransient
    public List<Titulopagar> getTitulopagarList() {
        return titulopagarList;
    }

    public void setTitulopagarList(List<Titulopagar> titulopagarList) {
        this.titulopagarList = titulopagarList;
    }

    public Condicaopagamento getCondicaoPagamento() {
        return condicaoPagamento;
    }

    public void setCondicaoPagamento(Condicaopagamento condicaoPagamento) {
        this.condicaoPagamento = condicaoPagamento;
    }

    public Compra getCompra() {
        return compra;
    }

    public void setCompra(Compra compra) {
        this.compra = compra;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idCondicoesCompra != null ? idCondicoesCompra.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Condicoescompra)) {
            return false;
        }
        Condicoescompra other = (Condicoescompra) object;
        if ((this.idCondicoesCompra == null && other.idCondicoesCompra != null) || (this.idCondicoesCompra != null && !this.idCondicoesCompra.equals(other.idCondicoesCompra))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "modelo.Condicoescompra[ idCondicoesCompra=" + idCondicoesCompra + " ]";
    }
    
}
